extends CenterContainer


var edit_data = null

onready var sprite_op = $PanelContainer/VBoxContainer/sprite/SpriteSelectPlus

onready var level_input = $PanelContainer/VBoxContainer/level/SpinBox
onready var star_op = $PanelContainer/VBoxContainer/star/OptionButton

signal close


func set_edit_data(data):
	self.edit_data = data
	
	if edit_data:
		sprite_op.set_value(data["pokeId"])
		level_input.value = data["level"]

		star_op.select(star_op.get_item_index(data["star"]))
	

func _on_cancel_button_up():
	MainTool.getUILayer().pop_ui()


func _on_ok_button_up():
	if edit_data:
		edit_data["pokeId"] = sprite_op.get_value()
		edit_data["star"] = star_op.get_selected_id()
		edit_data["level"] = level_input.value
			
		DataSource.update_data(DataSource.pick_sprite, edit_data)
		
		MainTool.toast_info("更新成功!")
	else:
		var data = {
			"pokeId": sprite_op.get_value(),
			"star": star_op.get_selected_id(),
			"level": level_input.value,
			"sex": 0,
			"natureId": 0,
		}
		
		DataSource.add_data(DataSource.pick_sprite, data)
	
		MainTool.toast_info("添加成功!")
	
	MainTool.getUILayer().pop_ui()
	
	emit_signal("close")
